#ifndef _MNGCSEAPI_H_CSEAPI_
#define _MNGCSEAPI_H_CSEAPI_

#include "CseApi.h";

#define self                       (*this)

#define _TINT_SIZEOF(n)            ((sizeof(n) + sizeof(TInt) - 1) & ~(sizeof(TInt) - 1))

#define MNG_TIER_BEGIN(AClass,ABase)  private: \
    static void* operator new(size_t); \
    static void* operator new(size_t,int); \
    static void operator delete(void*); \
    static void operator delete(void*,size_t); \
    const AClass* operator&() const; \
  public: \
    AClass(CseObj obj): ABase(obj) { } \
    AClass(const AClass& obj): ABase(obj.m_data) { } \
    class m_ { public:

#define MNG_TIER_END(AClass,ABase)  }; \
    class m: public ABase::m, public m_ { private: m(); m(const m& obj); }; \
    m *operator->() { return (m*) m_data->tValue; } \
    AClass() { } \
    void __init__() { \
        int iLen = _TINT_SIZEOF(m) / sizeof(TInt); \
        if (len() < iLen) resize(iLen); \
        setExitFunc(METHOD_ADDR(AClass,__exit__)); \
    }

#define MNG_BUFF_BEGIN(AClass,ABase)  MNG_TIER_BEGIN(AClass,ABase) 

#define MNG_BUFF_END(AClass,ABase)  }; \
    class m: public ABase::m, public m_ { private: m(); m(const m& obj); }; \
    m *operator->() { return (m*) m_data->bValue; } \
    void __init__() { \
        int iLen = sizeof(m) / sizeof(CseObj); \
        if (len() < iLen) resize(iLen); \
        m_ obj; int iLen_ = sizeof(obj) / sizeof(CseObj); \
        CseObj *pSour = (CseObj *) &obj; \
        for (int i = iLen - iLen_; i < iLen; i++,pSour++) sub(i) = *pSour; \
        setExitFunc(METHOD_ADDR(AClass,__exit__)); \
    }

#define PROP_INT(AClass,name)      TIntProp name; static TInt __ ## name(AClass& me,TIntObj& value,TInt* pValue)
#define PROP_WINT(AClass,name)     TWintProp name; static TWint __ ## name(AClass& me,TWintObj& value,TWint* pValue)
#define PROP_FLOAT(AClass,name)    TFloatProp name; static TDouble __ ## name(AClass& me,TFloatObj& value,TDouble* pValue)
#define PROP_STR(AClass,name)      TStrProp name; static const TXchar* __ ## name(AClass& me,TCharArray& value,const TXchar** pValue)

#define BIND_PROP(AClass,name)        (*this)->name.bindMethod((void*)this,(void*)&AClass::m_:: __ ## name)
#define PROP_FUNC_INT(AClass,name)    TInt AClass::m_:: __ ## name(AClass& me, TIntObj& value, TInt *pValue) {
#define PROP_FUNC_WINT(AClass,name)   TWint AClass::m_:: __ ## name(AClass& me, TWintObj& value, TWint *pValue) {
#define PROP_FUNC_FLOAT(AClass,name)  TDouble AClass::m_:: __ ## name(AClass& me, TFloatObj& value, TDouble *pValue) {
#define PROP_FUNC_STR(AClass,name)    const TXchar* AClass::m_:: __ ## name(AClass& me, TCharArray& value, const TXchar** pValue) {
#define PROP_FUNC_END                 if (pValue != NULL) value = *pValue; return value; }

#define BIND_PROP_(AClass,name)       name.bindMethod((void*)this,(void*)&AClass:: __ ## name)
#define PROP_FUNC_INT_(AClass,name)   TInt AClass:: __ ## name(AClass& me, TIntObj& value, TInt *pValue) {
#define PROP_FUNC_WINT_(AClass,name)  TWint AClass:: __ ## name(AClass& me, TWintObj& value, TWint *pValue) {
#define PROP_FUNC_FLOAT_(AClass,name) TDouble AClass:: __ ## name(AClass& me, TFloatObj& value, TDouble *pValue) {
#define PROP_FUNC_STR_(AClass,name)   const TXchar* AClass:: __ ## name(AClass& me, TCharArray& value, const TXchar** pValue) {
#define PROP_FUNC_END_                PROP_FUNC_END

#endif
